package com.yjf.ljr.activity;

import com.yjf.ljr.R;
import com.yjf.ljr.activity.IjActivity.ID;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class MobileDetailActivity extends IjActivity implements OnClickListener {
	@ID("rlchangeMobile")
	private RelativeLayout mRlChangeMobile;

	@ID("tvMobile")
	private TextView mTvMobile;
	private String mobile;// 手机号码 不展示
	private String viewMobile;// 手机号码 展示用
	static MobileDetailActivity instance;
	private static final int UPDATA_PHONE = 1007;
	
	@ID("phoneTip")
	private TextView phoneTip;
	
	private String modifyMobileUrl;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_mobile_detail);
		initControl();

	}

	private void initControl() {
		setLeftBtnClick();
		setTitleStr("手机绑定");
		instance = this;
		mobile = getIntent().getStringExtra("mobile");
		viewMobile = getIntent().getStringExtra("viewMobile");
		modifyMobileUrl = getIntent().getStringExtra("modifyMobileUrl");
		if (!TextUtils.isEmpty(viewMobile)) {
			mTvMobile.setText(viewMobile);
			phoneTip.setText("修改手机号");
		} else {
			phoneTip.setText("绑定手机号");
		}
		mRlChangeMobile.setOnClickListener(this);
		if(TextUtils.isEmpty(modifyMobileUrl)) {
			mRlChangeMobile.setVisibility(View.GONE);
		} else {
			mRlChangeMobile.setVisibility(View.VISIBLE);
		}
	}

	@Override
	public void onClick(View view) {
		// TODO Auto-generated method stub
		switch (view.getId()) {
		case R.id.rlchangeMobile:
			if(!TextUtils.isEmpty(modifyMobileUrl)) {
				Intent intent = new Intent(mContext, UpdatePhoneActivity.class);
				intent.putExtra("returnStr", "userManage/modifyMobileResult");
				intent.putExtra("mobile", mobile);
				intent.putExtra("viewMobile", viewMobile);
				intent.putExtra("modifyMobileUrl", modifyMobileUrl);
				startActivityForResult(intent, UPDATA_PHONE);
			}
			break;

		default:
			break;
		}
	}

	@Override
	protected void onActivityResult(int request, int result, Intent intent) {
		// TODO Auto-generated method stub
		super.onActivityResult(request, result, intent);
		if(request == UPDATA_PHONE) {
			setResult(RESULT_OK);
			finish();
			return;
		}
	}
}
